package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.vo.SkuDetailVo;
import com.atguigu.gmall.web.feign.ItemFeignClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Api(tags = "内部接口（thymeleaf渲染），商品详情页面")
@Controller
public class ItemController {

    @Autowired
    ItemFeignClient itemFeignClient;

    @ApiOperation("商品详情页")
    //路径的变量可以和字符串拼接在一起
    @GetMapping("/{skuId}.html")
    public String getItemDetail(@PathVariable Long skuId, Model model
    ) {
        //远程调用service-item 服务
        Result<SkuDetailVo> skuDetails = itemFeignClient.getSkuDetailVo(skuId);
        //todo skuDetailVo有可能为空
        SkuDetailVo skuDetailVo = skuDetails.getData();

        //1、分类视图(category1Id,category2Id,category3Id,category1Name,category2Name,category3Name)
        model.addAttribute("categoryView",skuDetailVo.getCategoryView());

        //2、sku信息（基本信息，图片列表）
        model.addAttribute("skuInfo",skuDetailVo.getSkuInfo());

        //3、实时价格
        model.addAttribute("price",skuDetailVo.getPrice());

        //4、spu销售属性集合
        model.addAttribute("spuSaleAttrList",skuDetailVo.getSpuSaleAttrList());

        //5、当前sku所有兄弟们的所有组合
        //返回格式{"118|120":49,"119|120":50}
        model.addAttribute("valuesSkuJson",skuDetailVo.getValueSkuJson());

        //todo 6、sku的规格；平台属性,暂时不做



        return "item/index";
    }
}
